"""
路径
"""

import logging
from urllib import parse

__all__ = [
    "get_safe_path",  # ->  获取路径安全的 Path
]

logger = logging.getLogger()


def get_safe_path(path: str) -> str:
    """
    获取路径安全的 Path 字符串

    - 无法解析的符号（9 个）: /   \   <   >   ?   :   "   |   *

    >>> get_safe_path("Hello World")
        "Hello World"

    >>> get_safe_path("Hello|World")
        "Hello%7CWorld"

    :param path:    Path 字符串
    :return:        文件夹路径安全的 Path 字符串
    """

    try:
        _path: str = str(path)

        for char in r'/\<>?:"|*':
            _path = _path.replace(char, parse.quote_plus(char))

        return _path

    except Exception as e:
        logger.error(f"【获取路径安全的 Path 字符串】错误：{e}")
